package ahblue.cn.tanzi.ui.person;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.widget.RelativeLayout;

import ahblue.cn.tanzi.R;
import ahblue.cn.tanzi.jmessage.im.util.DialogCreator;
import ahblue.cn.tanzi.model.user.CodeModel;
import ahblue.cn.tanzi.model.user.LoginResultModel;
import ahblue.cn.tanzi.ui.base.BaseActivity;
import ahblue.cn.tanzi.ui.person.pay.PayDialog;
import ahblue.cn.tanzi.ui.person.pay.WAPayNode;
import ahblue.cn.tanzi.util.PinkJSON;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * vip充值界面
 * Created by fengdongfei on 2018/12/1.
 */

public class VipActivity extends BaseActivity implements View.OnClickListener {
    private String etmoney = "18";
    private String viptype = "month";

    private RelativeLayout ll01, ll02, ll03, ll04;
    private Dialog mDialog;

    public static void into(Activity activity) {
        activity.startActivity(new Intent(activity, VipActivity.class));
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pay_vip_money);
        ButterKnife.bind(this);
        ll01 = findViewById(R.id.ll01);
        ll02 = findViewById(R.id.ll02);
        ll03 = findViewById(R.id.ll03);
        ll04 = findViewById(R.id.ll04);
        ll01.setOnClickListener(this);
        ll02.setOnClickListener(this);
        ll03.setOnClickListener(this);
        ll04.setOnClickListener(this);
    }

    @OnClick({R.id.btn_back, R.id.tvok})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_back:
                finish();
                break;
            case R.id.tvok:
                mDialog = DialogCreator.createLoadingDialog(this, "开始支付");
                mDialog.show();
                CodeModel.getVipOrderPayNo(VipActivity.this,  LoginResultModel.getToken(this),viptype, new CodeModel.DataVertifyListener() {
                    @Override
                    public void conver(String orderSn) {
                        WAPayNode.payVip(VipActivity.this, LoginResultModel.getToken(VipActivity.this), orderSn, "wx_app", new WAPayNode.VertifyListener() {
                            @Override
                            public void conver(WAPayNode b) {
                                mDialog.dismiss();
                                Log.d("WAPayNode", "conver: " + PinkJSON.toJSON(b));
                                PayDialog pay = new PayDialog(VipActivity.this, b);
                                pay.show();
                            }
                        });
                    }
                });
                break;
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll01:
                ll01.setBackground(getResources().getDrawable(R.drawable.strock_select));
                ll02.setBackground(getResources().getDrawable(R.drawable.strock_unselect));
                ll03.setBackground(getResources().getDrawable(R.drawable.strock_unselect));
                ll04.setBackground(getResources().getDrawable(R.drawable.strock_unselect));
                etmoney = "18";
                viptype = "month";
                break;
            case R.id.ll02:
                ll01.setBackground(getResources().getDrawable(R.drawable.strock_unselect));
                ll02.setBackground(getResources().getDrawable(R.drawable.strock_select));
                ll03.setBackground(getResources().getDrawable(R.drawable.strock_unselect));
                ll04.setBackground(getResources().getDrawable(R.drawable.strock_unselect));

                etmoney = "98";
                viptype = "quarter";
                break;
            case R.id.ll03:
                ll01.setBackground(getResources().getDrawable(R.drawable.strock_unselect));
                ll02.setBackground(getResources().getDrawable(R.drawable.strock_unselect));
                ll03.setBackground(getResources().getDrawable(R.drawable.strock_select));
                ll04.setBackground(getResources().getDrawable(R.drawable.strock_unselect));

                etmoney = "188";
                viptype = "year";
                break;
            case R.id.ll04:
                ll01.setBackground(getResources().getDrawable(R.drawable.strock_unselect));
                ll02.setBackground(getResources().getDrawable(R.drawable.strock_unselect));
                ll03.setBackground(getResources().getDrawable(R.drawable.strock_unselect));
                ll04.setBackground(getResources().getDrawable(R.drawable.strock_select));
                etmoney = "998";
                viptype = "lifetime";
                break;
        }
    }
}
